package kr.pe.johnkim.pushchat.mobile.controller;

import kr.pe.johnkim.pushchat.mobile.domain.PushChatBlock;
import kr.pe.johnkim.pushchat.mobile.service.PushChatBlockService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : John_Kim <cale9797@gmail.com>
 * @date : 2013. 12. 16.
 */
@Controller
@RequestMapping(value = "/pushChatBlockController")
public class PushChatBlockController {

    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(PushChatBlockController.class);

    @Autowired
    private PushChatBlockService pushChatBlockService;

    /**
     * 차단 중복을 확인 한다.
     *
     * @param pushChatBlock
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/selectDuplicationBlock", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public PushChatBlock selectDuplicationBlock(@RequestBody PushChatBlock pushChatBlock) throws Exception {
        logger.info("selectDuplicationBlock");
        return this.pushChatBlockService.selectDuplicationBlock(pushChatBlock);
    }
    /**
     * 차단을 등록 한다.
     *
     * @param pushChatBlock
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/registerBlock", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public PushChatBlock registerBlock(@RequestBody PushChatBlock pushChatBlock) throws Exception {
        logger.info("registerBlock");

        PushChatBlock result = new PushChatBlock();

        try {
            this.pushChatBlockService.registerBlock(pushChatBlock);
            result.setResult("SUCCESS");
            logger.info("success to register block.");
        } catch (Exception e) {
            result.setResult("FAIL");
            logger.error("fail to register block.");
        }

        return result;
    }

    /**
     * 차단 목록을 가져 온다.
     *
     * 1. 차단 당한 사용자 아이디를 입력하면 해당 사용자의 차단 목록을 가져 온다.
     * 2. 없으면 모든 목록을 가져 온다.
     * 3. 신고자 아이디를 입력하면 해당 신고자가 신고한 차단 목록을 가져 온다.
     * 4. 없으면 모든 목록을 가져 온다.
     *
     * @param pushChatBlock
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/selectBlockList", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public List<PushChatBlock> selectBlockList(@RequestBody PushChatBlock pushChatBlock) throws Exception {
        logger.info("selectBlockList");
        return this.pushChatBlockService.selectBlockList(pushChatBlock);
    }

    /**
     * 특정(차단당한) 사용자의 차단 총 갯수를 가져 온다.
     *
     * @param pushChatBlock
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/selectBlockTotalCount", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public PushChatBlock selectBlockTotalCount(@RequestBody PushChatBlock pushChatBlock) throws Exception {
        logger.info("selectBlockTotalCount");
        return this.pushChatBlockService.selectBlockTotalCount(pushChatBlock);
    }
}
